﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using phones.Repository;
using phones.Model;
using phones.ViewModel;
using phones.ViewModel.TreeViewModel;

namespace phones.ViewModel
{
    public class ServiceNodeTreeItemViewModel : TreeViewItemBaseViewModel
    {
        private ServiceNode _serviceNode;
        
        public ServiceNode Model
        { get { return _serviceNode; } }

        public ServiceNodeTreeItemViewModel(ServiceNode serviceNode)
            : base(null, true)
        {
            //db = new ServiceNodesRepository();
            //LoadChildren();
            _serviceNode = serviceNode;
        }

        protected override void LoadChildren()
        {
            Children.Clear();

            var db = new OrganisationsRepository();

            foreach (var zone in db.GetList(_serviceNode))
            {
                Children.Add(new OrganisationNodeTreeItemViewModel(this, zone));
            }
        }

        internal void Reload()
        {
            LoadChildren();
        }
    }
}
